package org.sction.support.spring;

import java.io.File;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class SpringStartup {
	/**
	 * 
	 * @param classpath
	 *            base:"projectpath" 为基础（运行）目录+projectpath
	 * @param xmls
	 */
	public static ApplicationContext springStartup(String classpath,
			String... xmls) {
		System.setProperty("projectpath", new File("").getAbsolutePath());
		System.out.println("基础目录：" + System.getProperty("projectpath"));

		if (classpath != null && !"".equals(classpath.trim())) {
			if (classpath.trim().startsWith("projectpath:")) {
				System.setProperty(
						"classpath",
						System.getProperty("projectpath")
								+ classpath.substring(12));
			} else {
				System.setProperty("classpath", classpath);
			}
		}
		System.out.println("类目录：" + System.getProperty("classpath"));
		return new FileSystemXmlApplicationContext(xmls);
	}
}
